home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
diag
/
memsz153.zip
/
DEBUG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-02
|
5KB
|
161 lines
/******************************************************************** DEBUG.C
* *
* Debugging Aids *
* *
****************************************************************************/
#define INCL_WIN
#include <os2.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "debug.h"
/****************************************************************************
* *
* Display Debug Message *
* *
****************************************************************************/
extern VOID Debug ( HWND hwnd, char *Message, ... )
{
/***************************************************************************
* Local Declarations *
***************************************************************************/
va_list Marker ;
char Text [500] ;
/***************************************************************************
* Format the debug message. *
***************************************************************************/
va_start ( Marker, Message ) ;
vsprintf ( Text, Message, Marker ) ;
va_end ( Marker ) ;
/***************************************************************************
* Display the log message and wait for the user to press ENTER. *
***************************************************************************/
WinMessageBox ( HWND_DESKTOP, hwnd, Text, "Debug", 0, MB_ENTER ) ;
}
/****************************************************************************
* *
* Log Debug Message *
* *
****************************************************************************/
extern VOID Log ( char *Message, ... )
{
/***************************************************************************
* Local Declarations *
***************************************************************************/
FILE *Log ;
va_list Marker ;
/***************************************************************************
* Try to open the log file. If unsuccessful, just return. *
***************************************************************************/
Log = fopen ( "LOG", "at" ) ;
if ( Log == NULL )
return ;
/***************************************************************************
* Format and write the message to the log file. *
***************************************************************************/
va_start ( Marker, Message ) ;
vfprintf ( Log, Message, Marker ) ;
va_end ( Marker ) ;
/***************************************************************************
* Close the log file and return. *
***************************************************************************/
fclose ( Log ) ;
}
/****************************************************************************
* *
* Open Timer for Use *
* *
****************************************************************************/
extern HFILE OpenTimer ( VOID )
{
HFILE Handle ;
USHORT Action ;
if ( DosOpen ( "TIMER$", &Handle, &Action, 0, FILE_NORMAL, FILE_OPEN, OPEN_SHARE_DENYNONE, 0 ) )
{
return ( -1 ) ;
}
return ( Handle ) ;
}
/****************************************************************************
* *
* Close Timer *
* *
****************************************************************************/
extern VOID CloseTimer ( HFILE Handle )
{
DosClose ( Handle ) ;
}
/****************************************************************************
* *
* Read Time from HRTIMER.SYS *
* *
****************************************************************************/
extern BOOL GetTime ( HFILE Handle, PTIMESTAMP pts )
{
USHORT ByteCount ;
if ( DosRead ( Handle, pts, sizeof(*pts), &ByteCount ) )
return ( FALSE ) ;
return ( TRUE ) ;
}
/****************************************************************************
* *
* Calculate Elapsed Time *
* *
****************************************************************************/
extern ULONG ElapsedTime ( PTIMESTAMP ptsStart, PTIMESTAMP ptsStop, PULONG pulNs )
{
ULONG ulMsecs, ulNsecs;
TIMESTAMP tsStart, tsStop ;
tsStart = *ptsStart ; // De-reference timestamp
// structures for speed
tsStop = *ptsStop ;
ulMsecs = tsStop.ulMs - tsStart.ulMs ; // Elapsed milliseconds
if( tsStart.ulNs > tsStop.ulNs ) // If nanosecond overflow ...
{
ulNsecs = (1000000 + tsStop.ulNs) - tsStart.ulNs; // Adjust nanoseconds
ulMsecs--; // Adjust milliseconds
}
else
ulNsecs = tsStop.ulNs - tsStart.ulNs ; // No overflow..Elapsed nanos
*pulNs = ulNsecs ;
return ( ulMsecs ) ;
}